<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../static/layui/layui-v2.9.7/layui/css/layui.css">
    <script src="../static/layui/layui-v2.9.7/layui/layui.js"></script>
    <script src="../static/jquery/main.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
            background-image: url("{{ url_for('static', filename='images/demo.png') }}");
            background-size: cover;
            background-position: center;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 24px; /* 设置字体大小 */
            
        }
    </style>
</head>

<body>
    <div class="layui-card layui-card-body" style="width: 350px;">
        <form class="layui-form">
            <div class="layui-form-item" style="display: flex; align-items: center; flex-direction: column;">
                <h3>选课系统</h3>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户名:</label>
                <div class="layui-input-block"> <input type="text" class="layui-input" id="username"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码:</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="password">
                </div>
            </div>
            <div class="layui-form-item" style="display: flex;align-items: center;flex-direction: column;">
                <button type="button" class="layui-btn layui-bg-blue" id="login">登录</button>
            </div>
        </form>
    </div>
    <script src="../static/task.js"></script>
    <script>
        $('#login').on('click', async function () {
            let username = $('#username').val()
            let password = $('#password').val()
            if (username == '' || password == '') {
                setTimeout(() => {
                    taskObject.layerErrorView('输入不能为空')
                }, 500)
                return;
            }
            response = await taskObject.fetchtemplate(path = '/login', method = 'POST', data = { 'username': username, 'password': password })

            if (response['code'] == 200) {

                setTimeout(() => {
                    taskObject.layerSuccessView('登录成功')
                }, 1000)
                setTimeout(() => {
                    window.location.href = '../'
                }, 1500)
                return;
            }

            setTimeout(() => {
                taskObject.layerErrorView(response['message'])
            }, 1500)
            return;

        })
    </script>
</body>

</html>